(* This is the compiler *)
(* It should output java source-code by walking the AST tree*)

open Ast
open Lsystemstd

exception RedeclarationOfStandardFunctionNotAllowedError

(* We should walk the AST and produce the corresponding Java Source Code *)
  
(*let string_of_vdecl id = "int " ^ id ^ ";\n"*)

let string_of_fdecl fdecl =
	if List.mem fdecl.fname Lsystemstd.func_names then 
		raise RedeclarationOfStandardFunctionNotAllowedError
	else
		let fun_sig =
		match fdecl.fname with
		"main" -> "public static void main(String[] args) {\n"
		| _ -> fdecl.fname ^ "(" ^ String.concat ", " fdecl.formals ^ ") {\n"
		  in fun_sig ^
		  String.concat "" (List.map string_of_vdecl fdecl.locals) ^
		  String.concat "" (List.map string_of_stmt fdecl.body) ^
		  "}\n"
		  	
let translate (funcs) =
  "public class Add {\n" ^
  (*String.concat "" (List.map string_of_vdecl vars) ^ "\n" ^ *)
  String.concat "\n" (List.map string_of_fdecl funcs)	
  ^ Lsystemstd.func_defs ^ " }"
  